package com.cms.plugin;

import com.cms.common.context.ApplicationContextProvider;
import com.cms.common.model.entity.Plugin;
import com.cms.plugin.services.PluginService;
import com.gitee.starblues.core.PluginInfo;
import com.gitee.starblues.core.checker.PluginLauncherChecker;
import com.gitee.starblues.core.exception.PluginException;
import org.springframework.stereotype.Component;

@Component
public class CustomPluginLauncherChecker implements PluginLauncherChecker {


    @Override
    public void checkCanStart(PluginInfo pluginInfo) throws PluginException {
        String pluginId = pluginInfo.getPluginId();
        PluginService pluginService = ApplicationContextProvider.getBean(PluginService.class);
        Plugin plugin = pluginService.findByPluginId(pluginId);
        if (plugin == null) {
            throw new PluginException("插件未安装");
        }
        if (!plugin.getEnabled()) {
            throw new PluginException("插件未启用");
        }
    }

    @Override
    public void checkCanStop(PluginInfo pluginInfo) throws PluginException {
        // 检查是否能停止
    }


}